<template>
  <div class="card">
    <div class="card-header" @click="showAppsDetail">
      <h3><i class="el-icon-star-off"></i> 我的应用</h3>
      <i class="el-icon-more"></i>
    </div>
    <div class="card-body">
      <div class="app-grid">
        <div v-for="(app, index) in myApps" :key="index" class="app-item" @click="openApp(app)">
          <div class="app-icon">{{ app.icon }}</div>
          <p class="app-name">{{ app.name }}</p>
        </div>
      </div>
    </div>

    <!-- 我的应用详情弹窗 -->
    <MyAppsDetail 
      :visible="isDetailVisible" 
      :apps="myApps"
      @close="hideAppsDetail"
    />
  </div>
</template>

<script>
import MyAppsDetail from './MyAppsDetail.vue';

export default {
  name: 'MyApps',
  components: {
    MyAppsDetail
  },
  data() {
    return {
      isDetailVisible: false,
      myApps: [
        { name: '采购系统', icon: '🛒' },
        { name: '维修系统', icon: '🔧' },
        { name: '流程审批', icon: '📝' },
        { name: '设备管理', icon: '💻' }
      ]
    }
  },
  methods: {
    openApp(app) {
      if (app.route) {
        this.$router.push(app.route)
      }
    },
    showAppsDetail() {
      this.isDetailVisible = true;
    },
    hideAppsDetail() {
      this.isDetailVisible = false;
    }
  }
}
</script>

<style scoped>
.card {
  background: #fff;
  border: 1px solid #e0e0e0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  background: #f8f9fa;
  cursor: pointer;
}

.card-header:hover {
  background-color: #f0f2f5;
}

.card-header h3 {
  margin: 0;
  font-size: 15px;
  color: #333;
  display: flex;
  align-items: center;
}

.card-header h3 i {
  margin-right: 8px;
  color: #666;
}

.card-body {
  padding: 12px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 8px;
  transition: all 0.2s;
}

.app-item:hover {
  background-color: #f5f7fa;
  transform: translateY(-2px);
}

.app-icon {
  font-size: 22px;
  margin-bottom: 6px;
}

.app-name {
  font-size: 12px;
  color: #333;
  text-align: center;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
</style>